home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue44 / Paradox / Lossu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-10-29  |  1.6 KB  |  74 lines

  1. unit LossU;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormCreate(Sender: TObject);
  12.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     procedure DoIdle(Sender: TObject; var Done: Boolean);
  17. {$ifdef VER80}
  18.     procedure WMEndSession(var Msg: TWMEndSession);
  19.       message wm_EndSession;
  20. {$endif}
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. uses
  29.   DbiProcs;
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. begin
  35.   Application.OnIdle := DoIdle;
  36. end;
  37.  
  38. procedure TForm1.DoIdle(Sender: TObject; var Done: Boolean);
  39. begin
  40.   { Each idle period, write a dirty buffer to disk }
  41.   DbiUseIdleTime;
  42.   Done := True;
  43. end;
  44.  
  45. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  46. var
  47.   Loop: Integer;
  48. begin
  49.   { Generic way of ensuring all }
  50.   { table changes are saved }
  51.   { when the form is closed }
  52.   for Loop := 0 to ComponentCount - 1 do
  53.    if Components[Loop] is TDataSet then
  54.      with TDataSet(Components[Loop]) do
  55.        if State in dsEditModes then
  56.          Post;
  57. end;
  58.  
  59. {$ifdef VER80}
  60. procedure TForm1.WMEndSession(var Msg: TWMEndSession);
  61. begin
  62.   { If session is ending, call Halt }
  63.   { to get exit routines executed. }
  64.   { The DB unit's exit routine frees }
  65.   { the Session object, which will }
  66.   { unload the BDE, flushing }
  67.   { any unsaved changes to disk }
  68.   if Msg.EndSession then
  69.     Halt;
  70. end;
  71. {$endif}
  72.  
  73. end.
  74.